package com.my.study.io.input;

import com.my.study.io.Dog;
import lombok.extern.slf4j.Slf4j;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

/**
 * @author Carlos
 * @version 1.0
 * @Description 反序列化
 *
 * 反序列化的顺序要与序列化保持一致 ！！！
 *
 * @date 2021/6/27 10:37
 **/
@Slf4j(topic = "c.ObjectInputStreamTest")
public class ObjectInputStreamTest {

    /**
     * 反序列化文件
     */
    private static final String PATH = "D:/file/dog.dat";

    public static void main(String[] args) {
        ObjectInputStream ois = null;

        try {
            ois = new ObjectInputStream(new FileInputStream(PATH));

            int intNum = ois.readInt();
            System.out.println(intNum);

            boolean bo = ois.readBoolean();
            System.out.println(bo);

            char c = ois.readChar();
            System.out.println(c);

            double readDouble = ois.readDouble();
            System.out.println(readDouble);

            String s = ois.readUTF();
            System.out.println(s);

            Dog dog = (Dog) ois.readObject();
            System.out.println(dog);
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            try {
                ois.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

}
